/*     */ package system.staros.cblock1;
/*     */ 
/*     */ public class Task extends Thread
/*     */ {
/*     */   public static final int maxMessages = 256;
/*     */   private int PID;
/*     */   private Task parent;
/*     */   private long starttime;
/*     */   private Scheduler scheduler;
/*     */   public static Message[] messages;
/*     */   public static boolean message_lock;
/*  19 */   public boolean running = true;
/*     */ 
/*     */   public Task()
/*     */   {
/*  25 */     this.parent = null;
/*  26 */     this.scheduler = null;
/*  27 */     setName("unknown");
/*     */   }
/*     */ 
/*     */   public Task(Task paramTask)
/*     */   {
/*  32 */     this.parent = paramTask;
/*  33 */     this.scheduler = null;
/*  34 */     setName("unknown");
/*     */   }
/*     */ 
/*     */   public Task(String paramString, Task paramTask) {
/*  38 */     super(paramString);
/*  39 */     this.parent = paramTask;
/*  40 */     this.scheduler = null;
/*  41 */     setName(paramString);
/*     */   }
/*     */ 
/*     */   public void setPID(int paramInt)
/*     */   {
/*  46 */     this.PID = paramInt;
/*     */   }
/*     */ 
/*     */   public int getPID() {
/*  50 */     return this.PID;
/*     */   }
/*     */ 
/*     */   public void setScheduler(Scheduler paramScheduler) {
/*  54 */     this.scheduler = paramScheduler;
/*     */   }
/*     */ 
/*     */   public Scheduler getScheduler() {
/*  58 */     if ((this.scheduler == null) && (this.parent != null)) {
/*  59 */       return this.parent.getScheduler();
/*     */     }
/*  61 */     return this.scheduler;
/*     */   }
/*     */ 
/*     */   public void setParent(Task paramTask) {
/*  65 */     this.parent = paramTask;
/*     */   }
/*     */ 
/*     */   public Task getParent() {
/*  69 */     return this.parent;
/*     */   }
/*     */ 
/*     */   public void setStarttime(long paramLong) {
/*  73 */     this.starttime = paramLong;
/*     */   }
/*     */ 
/*     */   public long uptime() {
/*  77 */     return System.currentTimeMillis() - this.starttime;
/*     */   }
/*     */ 
/*     */   public void lockMessage() {
/*  81 */     if (this.parent == null)
/*  82 */       message_lock = true;
/*     */     else
/*  84 */       this.parent.lockMessage();
/*     */   }
/*     */ 
/*     */   public void unlockMessage() {
/*  88 */     if (this.parent == null)
/*  89 */       message_lock = false;
/*     */     else
/*  91 */       this.parent.unlockMessage();
/*     */   }
/*     */ 
/*     */   public boolean isMessageLocked() {
/*  95 */     if (this.parent == null) {
/*  96 */       return message_lock;
/*     */     }
/*  98 */     return this.parent.isMessageLocked();
/*     */   }
/*     */ 
/*     */   public Message getMessage() {
/* 102 */     int i = getPID();
/* 103 */     return getMessage(i);
/*     */   }
/*     */ 
/*     */   public Message getMessage(int paramInt) {
/* 107 */     int i = 1;
/* 108 */     Message localMessage1 = null;
/* 109 */     Message localMessage2 = null;
/*     */ 
/* 111 */     if (this.parent == null)
/*     */     {
/* 114 */       for (int j = 0; j < 256; j++) {
/* 115 */         localMessage1 = messages[j];
/* 116 */         if ((localMessage1 != null) && 
/* 117 */           (!localMessage1.locked) && (!localMessage1.handled) && (localMessage1.PID_to == paramInt))
/* 118 */           if (i != 0) {
/* 119 */             localMessage2 = localMessage1;
/* 120 */             i = 0;
/*     */           }
/* 122 */           else if (localMessage1.time < localMessage2.time) {
/* 123 */             localMessage2 = localMessage1;
/*     */           }
/*     */       }
/*     */     }
/*     */     else {
/* 128 */       localMessage2 = this.parent.getMessage(paramInt);
/*     */     }
/* 130 */     return localMessage2;
/*     */   }
/*     */ 
/*     */   public boolean putMessage(Message paramMessage) {
/* 134 */     boolean bool = false;
/*     */ 
/* 136 */     while (isMessageLocked());
/* 138 */     lockMessage();
/*     */ 
/* 140 */     paramMessage.time = System.currentTimeMillis();
/*     */ 
/* 142 */     if (this.parent == null)
/*     */     {
/* 144 */       if (messages != null)
/* 145 */         for (int i = 0; i < 256; i++)
/* 146 */           if (messages[i] == null) {
/* 147 */             messages[i] = paramMessage;
/* 148 */             bool = true;
/* 149 */             break;
/*     */           }
/*     */     }
/*     */     else
/*     */     {
/* 154 */       unlockMessage();
/* 155 */       return this.parent.putMessage(paramMessage);
/*     */     }
/* 157 */     unlockMessage();
/* 158 */     return bool;
/*     */   }
/*     */ 
/*     */   public synchronized void print(String paramString)
/*     */   {
/* 163 */     Message localMessage = new Message();
/*     */ 
/* 165 */     localMessage.PID_from = getPID();
/* 166 */     localMessage.PID_to = 1;
/* 167 */     localMessage.ID = 100;
/* 168 */     localMessage.data_size = paramString.length();
/* 169 */     localMessage.data = new byte[paramString.length()];
/* 170 */     paramString.getBytes(0, paramString.length(), localMessage.data, 0);
/* 171 */     putMessage(localMessage);
/*     */   }
/*     */ 
/*     */   public void println(String paramString) {
/* 175 */     print(paramString);
/* 176 */     print("\n");
/*     */   }
/*     */ 
/*     */   public byte[] read()
/*     */   {
/* 181 */     byte[] arrayOfByte = null;
/* 182 */     Message localMessage = new Message();
/* 183 */     localMessage.PID_from = getPID();
/* 184 */     localMessage.PID_to = 2;
/* 185 */     localMessage.ID = 101;
/* 186 */     localMessage.data = null;
/* 187 */     localMessage.data_size = 0;
/* 188 */     putMessage(localMessage);
/*     */ 
/* 190 */     int i = 1;
/* 191 */     while (i != 0) {
/* 192 */       localMessage = getMessage(getPID());
/* 193 */       if ((localMessage != null) && 
/* 194 */         (localMessage.PID_from == 2)) {
/* 195 */         if (localMessage.ID == 100)
/* 196 */           localMessage.locked = true;
/* 197 */         arrayOfByte = new byte[localMessage.data_size];
/* 198 */         System.arraycopy(localMessage.data, 0, arrayOfByte, 0, localMessage.data_size);
/* 199 */         localMessage.handled = true;
/* 200 */         i = 0;
/*     */       }
/* 202 */       handleMessage();
/*     */     }
/* 204 */     return arrayOfByte;
/*     */   }
/*     */ 
/*     */   public void handleMessage() {
/* 208 */     Message localMessage = getMessage();
/* 209 */     if ((localMessage != null) && 
/* 210 */       (localMessage.PID_to == getPID())) {
/* 211 */       localMessage.locked = true;
/* 212 */       switch (localMessage.ID) {
/*     */       case 1:
/* 214 */         this.running = false;
/* 215 */         break;
/*     */       }
/*     */ 
/* 219 */       localMessage.handled = true;
/*     */     }
/*     */   }
/*     */ 
/*     */   public void run()
/*     */   {
/* 225 */     while (this.running)
/* 226 */       handleMessage();
/*     */   }
/*     */ 
/*     */   public int main(String[] paramArrayOfString)
/*     */   {
/* 231 */     run();
/* 232 */     return 0;
/*     */   }
/*     */ }

/* Location:           D:\Марк\!IMPORTANT\staros\archive\version-2.260.zip
 * Qualified Name:     system.staros.cblock1.Task
 * JD-Core Version:    0.6.1
 */